home *** CD-ROM | disk | FTP | other *** search
/ Technotools / Technotools (Chestnut CD-ROM)(1993).ISO / lang_c / cug231 / prime.st < prev    next >
Text File  |  1987-06-17  |  512b  |  26 lines

  1. Class Main
  2. [
  3.     main    | x gen |
  4.         gen <- Primes new.
  5.         (smalltalk time: [ x <- gen first.
  6.         [x < 300]
  7.             whileTrue: [ x print. x <- gen next] ] ) print.
  8. ]
  9. Class Primes
  10. | lastPrime |
  11. [
  12.     first
  13.         ^ lastPrime <- 2
  14. |
  15.     next
  16.         [lastPrime <- lastPrime + 1.
  17.          self testNumber: lastPrime]
  18.             whileFalse.
  19.         ^ lastPrime
  20. |
  21.     testNumber: n
  22.         (Primes new) do: [:x |
  23.             (x squared > n) ifTrue: [ ^ true ].
  24.             (n \\ x = 0) ifTrue: [ ^ false ] ]
  25. ]
  26.